home *** CD-ROM | disk | FTP | other *** search
- { dwin.pas -- TDlgWindow demonstration }
-
- program DWin;
-
- {$R list.res}
-
- uses WinTypes, WinProcs, WObjects, Strings;
-
- const
-
- id_Dialog = 200; { Dialog resource ID }
- id_Add = 101; { Dialog control IDs }
- id_Delete = 102;
- id_Input = 103;
- id_Listbox = 104;
- inputLen = 40; { Maximum length of input edit control }
-
- type
-
- DWinApplication = object(TApplication)
- procedure InitMainWindow; virtual;
- end;
-
- PDWinWindow = ^DWinWindow;
- DWinWindow = object(TDlgWindow)
- EditBox: PEdit;
- ListBox: PListBox;
- constructor Init(AParent: PWindowsObject; AName: PChar);
- procedure InitControls;
- procedure SetupWindow; virtual;
- procedure IDAdd(var Msg: TMessage);
- virtual id_First + id_Add;
- procedure IDDelete(var Msg: TMessage);
- virtual id_First + id_Delete;
- end;
-
-
- { DWinApplication }
-
- {- Initialize DWinApplication object's window }
- procedure DWinApplication.InitMainWindow;
- begin
- MainWindow := New(PDWinWindow, Init(nil, PChar(id_Dialog)))
- end;
-
-
- { DWinWindow }
-
- {- Construct DWinWindow object }
- constructor DWinWindow.Init(AParent: PWindowsObject; AName: PChar);
- begin
- TDlgWindow.Init(AParent, AName);
- InitControls
- end;
-
- {- Initialize control object child windows }
- procedure DWinWindow.InitControls;
- var
- AControl: PControl;
- begin
- AControl := New(PButton, InitResource(@Self, id_Add));
- AControl := New(PButton, InitResource(@Self, id_Delete));
- EditBox := New(PEdit, InitResource(@Self, id_Input, inputLen));
- ListBox := New(PListBox, InitResource(@Self, id_Listbox))
- end;
-
- {- Prepare initial control values }
- procedure DWinWindow.SetupWindow;
- begin
- TDlgWindow.SetupWindow;
- with ListBox^ do
- begin
- AddString('Apples');
- AddString('Peaches');
- AddString('Pumpkin');
- AddString('Pie')
- end
- end;
-
- {- Respond to selection of Add button }
- procedure DWinWindow.IDAdd(var Msg: TMessage);
- var
- Buffer: array[0 .. inputLen] of Char;
- begin
- EditBox^.GetText(Buffer, inputLen);
- if StrLen(Buffer) > 0 then
- begin
- ListBox^.AddString(Buffer);
- EditBox^.SetSelection(0, maxint)
- end
- end;
-
- {- Respond to selection of Delete button }
- procedure DWinWindow.IDDelete(var Msg: TMessage);
- var
- Item: Word; { Selected listbox-item index }
- begin
- Item := ListBox^.GetSelIndex;
- if Item >= 0 then
- begin
- ListBox^.DeleteString(Item);
- SetFocus(ListBox^.HWindow)
- end
- end;
-
- var
-
- DWinApp: DWinApplication;
-
- begin
- DWinApp.Init('DWinApp');
- DWinApp.Run;
- DWinApp.Done
- end.
-
-
- {--------------------------------------------------------------
- Copyright (c) 1991 by Tom Swan. All rights reserved.
- Revision 1.00 Date: 5/11/1991
- ---------------------------------------------------------------}
-